package com.ctbri.manage.file.util;

import java.util.List;

public class Page<T> {

    /** 每页展示的数据 */
    private int pageSize;

    /** 总条数 */
    private int totalSize;

    /** 当前页数 */
    private int pageIndex;

    /** 总页数 */
    private int totalPage;

    /** 查询开始记录 */
    private int start;

    private int status;
    private String message;
    
    private Object data;

    /** 数据集 */
    private List<T> dataList;

    private Object dataObject;


    /** 查询结束记录 */
    private int end;

    public Page() {
        this.pageSize = 10;
        this.totalSize = 0;
        this.pageIndex = 1;
        this.totalPage = 1;
        this.start = 0;
        this.end = this.pageSize;
        this.dataList = null;
        this.data=null;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
        if (totalSize <= pageSize) {
            totalPage = 1;
        } else {
            totalPage = totalSize % pageSize == 0 ? totalSize / pageSize : totalSize / pageSize + 1;
        }
        if (pageIndex > totalPage) {
            pageIndex = totalPage;
        }
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        setPageindex(pageIndex);
    }

    /**
     * 设置pageIndex时候自动计算要查询的条数
     * @param pageIndex
     */
    public void setPageindex(int pageIndex) {
        this.pageIndex = pageIndex;
        if(pageIndex > 0) {
            this.start = (this.pageIndex - 1) * this.pageSize;
        }else{
            this.start = 0;
        }
        this.end = this.start + this.pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getStart() {
        if(this.pageIndex > 0) {
            this.start = (this.pageIndex - 1) * this.pageSize;
        }else{
            this.start = 0;
        }
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return this.start + this.pageSize;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> data) {
        this.dataList = data;
        this.data=data;
    }



    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getDataObject() {
        return dataObject;
    }

    public void setDataObject(Object dataObject) {
        this.dataObject = dataObject;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
    
}
